<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IGMVC.Web.Models.IssueTypeListView>" %>
<%@ Register assembly="Infragistics.Web.Mvc" namespace="Infragistics.Web.Mvc" tagprefix="cc1" %>
<%@ Register Assembly="Infragistics4.Web.v10.2, Version=10.2.20102.2002, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	Issue Types
</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
<style type="text/css">
form{display:inline;}
</style>
<script type="text/javascript">
    function submitDelete(form) {
        var submit = confirm("Are you sure you want to delete this item?");
        if (submit) {
            form.action += "/" + $get("Id").value;
        }
        return submit;
    }

    function cancel(btn) {
        btn.parentNode.parentNode.style.display = "none";
        $get("delete").style.display = "inline";
    }

    function showAdd() {
        var frm = $get("inputForm").parentNode;
        frm.style.display = "block";
        frm.style.margin = "0px";
        frm.style.top = "230px";
        frm.style.left = "150px";
        $get("Title").value = "";
        $get("delete").style.display = "none";
    }
</script>
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <%
        this.issueTypes.DataSource = this.Model.IssueTypes;
        this.issueTypes.DataBind();
    %>

    <h2>Issue Types</h2>
    <form><!-- required for FireFox support of WebDataGrid RowEditTemplate --></form>
    <input type="button" value="Add" onclick="showAdd();" id="add" name="add" />
    <ig:WebDataGrid ID="issueTypes" AutoGenerateColumns="False" runat="server" Width="90%">
        <Columns>
            <ig:BoundDataField Header-Text="Id" DataFieldName="Id" Key="Id" />
            <ig:BoundDataField Header-Text="Title" DataFieldName="Title" Key="Title" />
        </Columns>
        <Behaviors>
            <ig:EditingCore>
                <Behaviors>
                    <ig:RowEditingTemplate>
                        <ClientBindings>
                            <ig:RowEditingClientBinding ColumnKey="Id" ControlID="Id" 
                                GetValueJavaScript="$get('Id').value" 
                                SetValueJavaScript="$get('Id').value={value}" />
                            <ig:RowEditingClientBinding ColumnKey="Title" ControlID="Title" 
                                GetValueJavaScript="$get('Title').value" 
                                SetValueJavaScript="$get('Title').value={value}" />
                        </ClientBindings>
                        <Template>
                            <div id="inputForm">
                            <form method="post" action="<%= Url.Action("Persist") %>">
                            <%= Html.Hidden("Id") %>
                            <%= Html.TextBox("Title") %>
                            <input type="submit" value="Save" />
                            </form>
                            
                            <form method="post" action="<%= Url.Action("Delete") %>" onsubmit="return submitDelete(this);">                          
                            <input type="submit" id="delete" name="delete" value="Delete" />                                   
                            </form>
                            
                            <input type="button" value="Cancel" onclick="cancel(this);" />
                            </div>
                        </Template>
                    </ig:RowEditingTemplate>
                </Behaviors>
            </ig:EditingCore>
            <ig:RowSelectors/>
            <ig:Selection CellClickAction="Row" CellSelectType="None" RowSelectType="Single">
            </ig:Selection>
        </Behaviors>
    </ig:WebDataGrid>

    <cc1:IGMvcScriptManager ID="sm" runat="server" />     

</asp:Content>

<asp:Content ContentPlaceHolderID="DescriptionContent" runat="server">
    <h3>On this Page</h3>
    <p>The WebDataGrid's RowEditTemplate is customized to submit new and existing
    issue types to the appropriate controller actions. Try double-clicking on the 
    far left cell in any row to open an item editor. Alternatively you may add
    new issue types by clicking the 'Add' button. Once you've added an issue type, 
    return to the <%= Html.ActionLink("new issue","Index","Issues") %> page to
    see your new entry in the drop down.</p>
</asp:Content>
